import _ from 'lodash'
import readline from 'readline'
import fs from "fs";
import selectUserList from "./selectUser.json" assert {type: "json"};

let user = ["大帝", "老陆", "卡斯", "文庆", "娜娜", "赵盟", "安全", "胡斌", '雅茹',
    '唐琛炜', '庞庞', '小雪', '从秦', '朱翔', '焱如', "姐夫", "鞠剑", '孟贵', "龙哥", '傅豫', '刘彬', '冯娇', "达哥",]


let saveJson = (pathStr, data) => {
    fs.writeFileSync(pathStr, JSON.stringify(data), 'utf-8');
}

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
console.log(`已经选过(${selectUserList.length}人)`, selectUserList);
let selectUser = () => {

    rl.question('\n是否下一个(Y/N)', (code) => {
        console.log(`已经选过(${selectUserList.length}人)`, (selectUserList));
        if (code.toUpperCase() === "Y") {
            let list = user.filter(item => !selectUserList.includes(item))
            console.log(`还未选择的有(${list.length}人)`, list);
            let curUser = _.shuffle(list)[0]
            selectUserList.push(curUser)
            saveJson("./selectUser.json", (selectUserList))
            console.log("本次选中的是：", curUser,`剩余${list.length-1}人`);

            if (selectUserList.length < user.length) {
                selectUser()
            } else {
                console.log("已经完毕了！！！")
            }
        } else {
            selectUser()
        }
    })

}

selectUser()